/* by wildw1ng */

[] spawn
{
	private ["_markerUIDs","_markerUnits","_units","_unit","_index","_indexes","_markerFormat", "_markerType"];
	_markerUIDs = [];
	_markerUnits = [];
	switch (true) do {
		case (playerSide == west): { _markerFormat = "respawn_west_%1"; _markerType = "b_inf"; };
		case (playerSide == east): { _markerFormat = "respawn_east_%1"; _markerType = "o_inf"; };
		case (playerSide == resistance): { _markerFormat = "respawn_guerrila_%1"; _markerType = "n_inf"; };
	};
	while {true} do
	{
		_indexes = [];
		_units = units (group player);
		{
			_unit = _x;
			if (_unit != player && isplayer _unit) then {
				_index = _markerUIDs find (getPlayerUID _unit);
				if (_index < 0) then {
					_index = count _markerUIDs;
					_markerUIDs set [_index, (getPlayerUID _unit)];
				};
				_marker = format[_markerFormat,_index];
				if (count _markerUnits <= _index) then {
					_markerUnits set [_index, _marker];
				};
				if (alive _unit) then {
					_indexes set [count _indexes, _index];
					if (markerType _marker == "") then {
						createMarkerLocal [_marker, getpos _unit];
					};
					_marker setmarkerposLocal getpos _unit;
					_text = name _unit;
					if (_unit == leader player) then {
						_marker setMarkerTextLocal "Squad Leader: " + _text;
					} else {
						_marker setMarkerTextLocal "Team mate: " + _text;
					};
					_marker setMarkerTypeLocal _markerType;
					_marker setMarkerAlphaLocal 0;
				};
			};
		} foreach _units;
		{
			if !(_forEachIndex in _indexes) then {
				if (markerType _x != "") then {
					deleteMarkerLocal _x;
				};
			};
		} foreach _markerUnits;
		sleep 1.0;
	};
};